package com.asiainfo.springcloud.manager;

import de.codecentric.boot.admin.config.EnableAdminServer;
import de.codecentric.boot.admin.config.NotifierConfiguration;
import de.codecentric.boot.admin.notify.MailNotifier;
import de.codecentric.boot.admin.notify.SlackNotifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


@Configuration
@EnableAdminServer //激活spring-boot-admin,集群中有一个就够了
@RestController
@SpringBootApplication
@EnableTurbine
public class ScAdminServer extends WebMvcConfigurerAdapter {
    private static final Logger logger = LoggerFactory.getLogger(ScAdminServer.class);

    @RequestMapping("/test")
    public String home() {
        logger.info("Hello World,here is  a spring-boot-adminserver");
        logger.trace("trace 成功了");
        logger.debug("debug 成功了");
        logger.info("info 成功了");
        logger.warn("warn 成功了");
        logger.error("error 成功了");
        return "Hello World,here is  a sc-demo";
    }

    public static void main(String[] args) {
        ApplicationContext ctx =  SpringApplication.run(ScAdminServer.class, args);
//        String[] beanNames =  ctx.getBeanDefinitionNames();
//
//        System.out.println("beanNames个数："+beanNames.length);
//
//        for(String bn:beanNames){
//
//            System.out.println(bn);
//
//        }
    }

    @Configuration
    public static class SecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll();
            http.logout().logoutUrl("logout");
            http.csrf().disable();
            http.authorizeRequests().antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**").permitAll();
            http.authorizeRequests().antMatchers("/**").authenticated();
            http.httpBasic();
        }
    }
}



